const ERROR = {
	// 通用错误
	PARAM_ERROR: 'param-error',
	PARAM_REQUIRED: 'param-required',
	SYSTEM_ERROR: 'system-error',
	OPERATION_SUCCESS: 'operation-success',
	OPERATION_FAILED: 'operation-failed',
	INVALID_CLIENT_INFO: 'invalid-client-info',
	UNSUPPORTED_REQUEST: 'unsupported-request',
	
	// 业务错误
	DICT_TYPE_REQUIRED: 'dict-type-required',
	DICT_GET_SUCCESS: 'dict-get-success',
	DICT_GET_FAILED: 'dict-get-failed',
	GET_DICT_ITEMS_FAILED: 'dict-get-failed',
	PATTERN_CATEGORIES_GET_FAILED: 'pattern-categories-get-failed',
	FEATURED_PLAYLIST_TYPES_GET_FAILED: 'featured-playlist-types-get-failed',
	
	// 图案相关错误
	PATTERN_GET_FAILED: 'pattern-get-failed',
	PATTERN_NOT_FOUND: 'pattern-not-found',
	PATTERN_LIST_GET_FAILED: 'pattern-list-get-failed',
	
	// 设备相关错误
	DEVICE_NOT_FOUND: 'device-not-found',
	DEVICE_REGISTER_FAILED: 'device-register-failed',
	DEVICE_UPDATE_FAILED: 'device-update-failed',
	DEVICE_LIST_GET_FAILED: 'device-list-get-failed',
	DEVICE_DETAIL_GET_FAILED: 'device-detail-get-failed',
	DEVICE_ACTIVE_UPDATE_FAILED: 'device-active-update-failed',
	DEVICE_DISABLE_FAILED: 'device-disable-failed',
	DEVICE_ENABLE_FAILED: 'device-enable-failed',
	
	// 收藏集相关错误
	COLLECTION_NOT_FOUND: 'collection-not-found',
	COLLECTION_EXISTS: 'collection-exists',
	COLLECTION_CREATE_FAILED: 'collection-create-failed',
	COLLECTION_UPDATE_FAILED: 'collection-update-failed',
	COLLECTION_DELETE_FAILED: 'collection-delete-failed',
	CANNOT_DELETE_DEFAULT: 'cannot-delete-default',
	PATTERN_EXISTS: 'pattern-exists',
	PATTERN_NOT_IN_COLLECTION: 'pattern-not-in-collection',
	
	// 播放列表相关错误
	PLAYLIST_NOT_FOUND: 'playlist-not-found',
	PLAYLIST_CREATE_FAILED: 'playlist-create-failed',
	PLAYLIST_UPDATE_FAILED: 'playlist-update-failed',
	PATTERN_ALREADY_IN_PLAYLIST: 'pattern-already-in-playlist',
	PATTERN_NOT_IN_PLAYLIST: 'pattern-not-in-playlist',
	DEVICE_ACCESS_DENIED: 'device-access-denied',
	
	// 喜欢相关错误
	FAVOURITE_NOT_FOUND: 'favourite-not-found',
	PATTERN_ALREADY_IN_FAVOURITE: 'pattern-already-in-favourite',
	PATTERN_NOT_IN_FAVOURITE: 'pattern-not-in-favourite',
	
	// 消息相关错误
	MESSAGE_NOT_FOUND: 'message-not-found',
	MESSAGE_SEND_FAILED: 'message-send-failed',
	MESSAGE_DELETE_FAILED: 'message-delete-failed',
	MESSAGE_UPDATE_FAILED: 'message-update-failed',
	MESSAGE_READ_FAILED: 'message-read-failed',
	
	// 分享相关错误
	SHARE_NOT_FOUND: 'share-not-found',
	SHARE_ALREADY_EXISTS: 'share-already-exists',
	SHARE_INVALID_CODE: 'share-invalid-code',
	SHARE_ALREADY_PROCESSED: 'share-already-processed',
	SHARE_EXPIRED: 'share-expired',
	SHARE_CREATE_FAILED: 'share-create-failed',
	SHARE_ACCEPT_FAILED: 'share-accept-failed',
	SHARE_REJECT_FAILED: 'share-reject-failed',
	SHARE_REVOKE_FAILED: 'share-revoke-failed',
	USER_NOT_FOUND: 'user-not-found',
	
	// 数据相关错误
	DATA_NOT_FOUND: 'data-not-found',
	
	// 数据库操作错误
	DATABASE_CONNECTION_FAILED: 'database-connection-failed',
	DATABASE_QUERY_FAILED: 'database-query-failed',
	
	// 权限相关错误
	PERMISSION_DENIED: 'permission-denied',
	UNAUTHORIZED: 'unauthorized'
}

function isUniIdError (errCode) {
  return Object.values(ERROR).includes(errCode)
}

class UniCloudError extends Error {
  constructor (options) {
    super(options.message)
    this.errMsg = options.message || ''
    this.errCode = options.code
  }
}

module.exports = {
  ERROR,
  isUniIdError,
  UniCloudError
}
